package com.d3works.apps.businesssupport.service.web;

import com.d3works.apps.project.service.ProjectActivityDashboardService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Singleton
public class ProjectActivityDashboardController {

  public void getData(ActionRequest request, ActionResponse response) {
    LocalDate annoucementDate =
        LocalDate.parse(
            request.getContext().get("announcementDate").toString(), DateTimeFormatter.ISO_DATE);
    LocalDate toDate = annoucementDate.plusDays(30);
    LocalDate todayDate = LocalDate.now();
    if (todayDate.isBefore(toDate)) {
      toDate = todayDate;
    }
    response.setValues(
        Beans.get(ProjectActivityDashboardService.class).getData(annoucementDate, toDate, null));
  }
}
